﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.IBLL;

namespace KPIS.GERP.GHRMS.BLL
{
    public class MasCityBLL : IMasCityBLL
    {
        private static readonly IMasCityDAL dal = DataAccess.CreateMasterCity();

        private MasCityInfo cityInfo = new MasCityInfo();
        private MasCountryInfo countryInfo = new MasCountryInfo();
        public DataSet LoadMasCities(Nullable<int> Sequence, Nullable<int> CountrySequence)
        {
            MasCityInfo cInfo = new MasCityInfo();
            MasCountryInfo ctInfo = new MasCountryInfo();

            cInfo.Sequence = Sequence.HasValue ? (int)Sequence : 0;
            ctInfo.Sequence = CountrySequence.HasValue ? (int)CountrySequence : 0;
            cInfo.Countries = ctInfo;

            return dal.LoadMasCities(cInfo);
        }        
        public IList<MasCityInfo> ListMasCities()
        {
            return dal.ListMasCities(new MasCityInfo(0)); //, "", "", new MasCountryInfo(CountrySeq), "", null, null));
        }
        public IList<MasCityInfo> ListMasCities(string Sequence, string Country)
        {
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            Nullable<int> CountrySeq = Country.Length > 0 ? Int32.Parse(Country) : 0;

            return dal.ListMasCities(new MasCityInfo(Seq, "", "", new MasCountryInfo(CountrySeq), "", 0, 0));
        }
        public void Insert(string Name, string NameEng, string Remarks, int Countries, int CreatedBy)
        {
            countryInfo.Sequence = Countries;

            try
            {
                dal.Insert(new MasCityInfo(0, Name, NameEng, countryInfo, Remarks, CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }

        }
        public void Update(int Sequence, string Name, string NameEng, string Remarks, int Countries, int UpdatedBy)
        {
            countryInfo.Sequence = Countries;

            try
            {
                dal.Update(new MasCityInfo(Sequence, Name, NameEng, countryInfo, Remarks, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }

        }

        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
        
    }
}
